package top.toptimus.dto.material;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

/**
 * 物料全部基础信息DTO
 *
 * @author gaoyu
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MaterialAllInfoDTO {
    private static final Logger logger = LoggerFactory.getLogger(MaterialAllInfoDTO.class);
    protected String id;    //  ID
    protected String vendorName;    //  供货商
    protected String materialNo;    //  面料号
    protected String meterialDesc;    //  描述名称
    protected String composition;    //  成分
    protected String density;    //  纱织密度
    protected String weight;    //  克重
    protected String width;    //  幅宽
    protected String thick;    //  厚度
    protected String elastic;    //  弹力
    protected String feature;    //  面料特性注意
    protected String continuity;    //  延续性
    protected String uasge;    //  用途
    protected String inspectionResults;    //  验料结果
    protected String color;    //  颜色
    protected String season;    //  季节
    protected String style;    //  风格
    protected String arrangementMethod;    //  整理方式

    /**
     * 查询
     *
     * @param resultSet 结果集
     * @throws SQLException exception
     */
    MaterialAllInfoDTO(ResultSet resultSet) throws SQLException {
        this.id = resultSet.getString("id");
        this.vendorName = resultSet.getString("vendor_name");
        this.materialNo = resultSet.getString("material_no");
        this.meterialDesc = resultSet.getString("meterial_desc");
        this.composition = resultSet.getString("composition");
        this.density = resultSet.getString("density");
        this.weight = resultSet.getString("weight");
        this.width = resultSet.getString("width");
        this.thick = resultSet.getString("thick");
        this.elastic = resultSet.getString("elastic");
        this.feature = resultSet.getString("feature");
        this.continuity = resultSet.getString("continuity");
        this.uasge = resultSet.getString("uasge");
        this.inspectionResults = resultSet.getString("inspection_results");
        this.color = resultSet.getString("color");
        this.season = resultSet.getString("season");
        this.style = resultSet.getString("style");
        this.arrangementMethod = resultSet.getString("arrangement_method");
    }


    /**
     * 查询
     */
    MaterialAllInfoDTO(Map<String, Object> stringObjectMap) {
        this.id = stringObjectMap.containsKey("id") && (stringObjectMap.get("id") != null) ? stringObjectMap.get("id").toString() : "";
        this.vendorName = stringObjectMap.containsKey("vendor_name") && (stringObjectMap.get("vendor_name") != null) ? stringObjectMap.get("vendor_name").toString() : "";
        this.materialNo = stringObjectMap.containsKey("material_no") && (stringObjectMap.get("material_no") != null) ? stringObjectMap.get("material_no").toString() : "";
        this.meterialDesc = stringObjectMap.containsKey("meterial_desc") && (stringObjectMap.get("meterial_desc") != null) ? stringObjectMap.get("meterial_desc").toString() : "";
        this.composition = stringObjectMap.containsKey("composition") && (stringObjectMap.get("composition") != null) ? stringObjectMap.get("composition").toString() : "";
        this.density = stringObjectMap.containsKey("density") && (stringObjectMap.get("density") != null) ? stringObjectMap.get("density").toString() : "";
        this.weight = stringObjectMap.containsKey("weight") && (stringObjectMap.get("weight") != null) ? stringObjectMap.get("weight").toString() : "";
        this.width = stringObjectMap.containsKey("width") && (stringObjectMap.get("width") != null) ? stringObjectMap.get("width").toString() : "";
        this.thick = stringObjectMap.containsKey("thick") && (stringObjectMap.get("thick") != null) ? stringObjectMap.get("thick").toString() : "";
        this.elastic = stringObjectMap.containsKey("elastic") && (stringObjectMap.get("elastic") != null) ? stringObjectMap.get("elastic").toString() : "";
        this.feature = stringObjectMap.containsKey("feature") && (stringObjectMap.get("feature") != null) ? stringObjectMap.get("feature").toString() : "";
        this.continuity = stringObjectMap.containsKey("continuity") && (stringObjectMap.get("continuity") != null) ? stringObjectMap.get("continuity").toString() : "";
        this.uasge = stringObjectMap.containsKey("uasge") && (stringObjectMap.get("uasge") != null) ? stringObjectMap.get("uasge").toString() : "";
        this.inspectionResults = stringObjectMap.containsKey("inspectionResults") && (stringObjectMap.get("inspectionResults") != null) ? stringObjectMap.get("inspectionResults").toString() : "";
        this.color = stringObjectMap.containsKey("color") && (stringObjectMap.get("color") != null) ? stringObjectMap.get("color").toString() : "";
        this.season = stringObjectMap.containsKey("season") && (stringObjectMap.get("season") != null) ? stringObjectMap.get("season").toString() : "";
        this.style = stringObjectMap.containsKey("style") && (stringObjectMap.get("style") != null) ? stringObjectMap.get("style").toString() : "";
        this.arrangementMethod = stringObjectMap.containsKey("arrangement_method") && (stringObjectMap.get("arrangement_method") != null) ? stringObjectMap.get("arrangement_method").toString() : "";
    }

    public String buildInsertSQL() {
        return "insert into i_material_p (MATERIAL_CODE,MATERIAL_NAME_CN,MATERIAL_COMPOSITION,MATERIAL_SAMPLE,MATERIAL_SOURCE,ENABLE_FLAG,DELETE_FLAG,MATERIAL_TYPE_CD) " +
                "values('" + this.materialNo + "'" +
                ",'" + this.meterialDesc + "'" +
                ",'" + this.composition + "','0','MATERIAL_SOURCE-CUSTOMER','1','0','MATERIAL_TYPE-20');";
    }

    /**
     * 导入临时DTO
     * TODO
     */
    public MaterialAllInfoDTO(String materialNo, String meterialDesc, String composition, String width, String color, String weight
            , String density, String thick, String elastic, String season, String style, String arrangementMethod, String vendorName) {
        this.materialNo = materialNo;
        this.meterialDesc = meterialDesc;
        this.composition = composition;
        this.width = width;
        this.color = color;
        this.weight = weight;
        this.density = density;
        this.thick = thick;
        this.elastic = elastic;
        this.season = season;
        this.style = style;
        this.arrangementMethod = arrangementMethod;
        this.vendorName = vendorName;
    }

    public MaterialAllInfoDTO(
            String vendorName,
            String materialNo,
            String meterialDesc,
            String composition,
            String density,
            String weight,
            String width,
            String thick,
            String elastic,
            String feature,
            String continuity,
            String uasge
    ) {
        this.vendorName = vendorName;
        this.materialNo = materialNo;
        this.meterialDesc = meterialDesc;
        this.composition = composition;
        this.density = density;
        this.weight = weight;
        this.width = width;
        this.thick = thick;
        this.elastic = elastic;
        this.feature = feature;
        this.continuity = continuity;
        this.uasge = uasge;
    }

    /**
     * 更新面料信息大连云erp表
     *
     * @return sql
     */
    public String buildUpdateSql() {
        String sql = "update t_material_info\n" +
                "set vendor_name='" + this.vendorName + "',\n" +
                "material_no='" + this.materialNo + "',\n" +
                "meterial_desc='" + this.meterialDesc + "',\n" +
                "composition='" + this.composition + "',\n" +
                "density='" + this.density + "',\n" +
                "weight='" + this.weight + "',\n" +
                "width='" + this.width + "',\n" +
                "thick='" + this.thick + "',\n" +
                "elastic='" + this.elastic + "',\n" +
                "feature='" + this.feature + "',\n" +
                "continuity='" + this.continuity + "',\n" +
                "uasge='" + this.uasge + "',\n" +
                "inspection_results='" + this.inspectionResults + "',\n" +
                "color='" + this.color + "',\n" +
                "season='" + this.season + "',\n" +
                "style='" + this.style + "',\n" +
                "arrangement_method='" + this.arrangementMethod + "'\n" +
                "where id = '" + this.id + "';";
        logger.info(sql);
        return sql;
    }
}
